<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-productResource-edit" th:object="${productResource}">
            <input id="id" name="id" th:field="*{id}"  type="hidden">
			<input name="productVersionId"  type="hidden" id="treeId" th:field="*{productVersionId}"/>
			<div class="form-group">
				<label class="col-sm-3 control-label">所属产品版本：</label>
				<div class="col-sm-8">
					<span class="label label-success" id = "productName" th:text="*{productVersion.productName}" style="display: inline-block;margin-bottom: 3px">productName</span>
					<input class="form-control" type="text" name="version" onclick="selectProductVersionTree()" readonly="true" id="treeName" th:field="*{version}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">资源类型：</label>
				<div class="col-sm-8">
					<select id="resourceType" name="resourceType" th:with="type=${@dict.getType('sys_product_resource_type')}" class="form-control m-b">
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{resourceType}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">适用系统：</label>
				<div class="col-sm-8">
					<select id="systemType" name="systemType" th:with="type=${@dict.getType('sys_system_type')}" class="form-control m-b">
						<option value="">无</option>
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{systemType}" ></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">是否增量：</label>
				<div class="col-sm-8">
					<select id="isIncrement" name="isIncrement" th:with="type=${@dict.getType('sys_is_increment')}" class="form-control m-b">
						<option value="">无</option>
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{isIncrement}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">资源存储的相对路径：</label>
				<div class="col-sm-8">
					<input id="resourceRelativePath" name="resourceRelativePath" th:field="*{resourceRelativePath}" class="form-control" type="text" readonly="true">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">重新上传文件：</label>
				<div class="col-sm-8">
					<input type="file" name="fileName"/>
					<!--<input id="resourceRelativePath" name="resourceRelativePath" class="form-control" type="text">-->
				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "system/productResource"
		$("#form-productResource-edit").validate({
			rules:{
                rules:{
                    version:{
                        required:true,
                    },
                    resourceType:{
                        required:true,
                    },
                    resourceName:{
                        required:true,
                    }
                }
			}
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
                edit();
	            // $.operate.save(prefix + "/edit", $('#form-productResource-edit').serialize());
	        }
	    }

        function edit() {
            var formData = new FormData($("#form-productResource-edit")[0]);
            $.ajax({
                cache : true,
                type : "POST",
                url : prefix + "/edit",
                data : formData,
                contentType:false,
                processData:false,
                mimeType:"multipart/form-data",
                error : function(request) {
                    $.modal.alertError("系统错误");
                },
                success : function(data) {
                    var jData = $.parseJSON(data);
                    $.operate.successCallback(jData);
                }
            });
        }


        /*产品资源-新增-选择产品版本树*/
        function selectProductVersionTree() {
            var url = ctx + "system/productVersion/selectProductVersionTree";
            var options = {
                title: '选择产品版本',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                $("#productName").text(body.find('#productName').val());
                layer.close(index);
            }
        }
	</script>
</body>
</html>
